<?php
include"config.php";

if (!empty($_FILES["picture"]["tmp_name"])){
	$jenis_gambar = $_FILES['picture']['type'];
	//echo $jenis_gambar;
	$namafolder="assets/picture/";
	$item_name=$_POST['item_name'];
	$cattegory = $_POST['cattegory'];
	$mark = $_POST['mark'];
	$tipe = $_POST['tipe'];
	if(isset($_REQUEST['cattegory'])){
		if($_REQUEST['cattegory'] == 'duration'){
			$gcash1 = $_POST['gcash1'];
			$gcash3 = $_POST['gcash3'];
			$gcash7 = $_POST['gcash7'];
			$gcash30 = $_POST['gcash30'];
			$point1 = $_POST['point1'];
			$point3 = $_POST['point3'];
			$point7 = $_POST['point7'];
			$point30 = $_POST['point30'];
		}elseif($_REQUEST['cattegory'] == 'consumable'){
			$unit_1 = $_POST['unit_1'];
			$unit_2 = $_POST['unit_2'];
			$point_price_1 = $_POST['point_price_1'];
			$point_price_2 = $_POST['point_price_2'];
			$cash_price_1 = $_POST['cash_price_1'];
			$cash_price_2 = $_POST['cash_price_2'];
		}
	}
	$description = $_POST['description'];
	$status = $_POST['status'];
	if($jenis_gambar=="image/jpeg" || $jenis_gambar=="image/jpg" || $jenis_gambar=="image/gif" || $jenis_gambar=="image/png"){
		//echo"a";
		$gambar = $namafolder . basename($_FILES['picture']['name']);
		$judul_gambarnya = $_FILES['picture']['name'];
		if (move_uploaded_file($_FILES['picture']['tmp_name'], $gambar)){
			//echo"b";
			if($cattegory == 'duration'){
				$sql="insert into tbl_item_duration(id_item, picture, item_name, cattegory, mark, tipe, gcash1, gcash3, gcash7, gcash30, point1, point3, point7, point30, description, status)values('', '$judul_gambarnya', '$item_name', '$cattegory', '$mark', '$tipe', '$gcash1', '$gcash3', '$gcash7', '$gcash30', '$point1', '$point3', '$point7', '$point30', '$description', '$status')";
			
			}elseif($cattegory == 'consumable'){
				$sql="insert into tbl_item_consumable(id_item, picture, item_name, cattegory, mark, tipe, unit_1, unit_2, point_price_1, point_price_2, cash_price_1, cash_price_2, description, status)values('', '$judul_gambarnya', '$item_name', '$cattegory', '$mark', '$tipe', '$unit_1', '$unit_2', '$point_price_1', '$point_price_2', '$cash_price_1', '$cash_price_2', '$description', '$status')";
			
			}
			$res=mysql_query($sql) or die (mysql_error());
			
			header("location:index.php?page=item");
		}else{
			echo "Gambar gagal dikirim";
		}
	}else{
		echo "Jenis gambar yang anda kirim salah. Harus .jpg .gif .png";
}
		}else{
			echo "Anda belum memilih gambar";
		}
?>